package cn.qingyun.gis.modules.baogan.controller;

import cn.qingyun.gis.common.Result;
import cn.qingyun.gis.modules.baogan.service.IPoiScenarioAdminService;
import cn.qingyun.gis.modules.baogan.vo.PoiScenarioLikeRequest;
import cn.qingyun.gis.modules.baogan.vo.request.*;
import cn.qingyun.gis.modules.baogan.vo.response.MicroGridBaseInfoVo;
import io.swagger.annotations.ApiOperation;
import org.locationtech.jts.io.ParseException;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author LHJ
 * @description
 * @date 2024/11/11 9:34
 */
@RestController
@RequestMapping("/admin/poi/")
public class PoiScenarioAdminController {
    @Resource
    private IPoiScenarioAdminService poiScenarioAdminService;

    /**
     * 根据关键字查询
     *
     * @param request
     * @return
     */
    @PostMapping("/query/keyword")
    @ApiOperation(value = "管理后台-关键字搜索新接口")
    public Result<?> poiSelectByWord(@Validated @RequestBody PoiScenarioLikeRequest request) {
        return Result.okData(poiScenarioAdminService.selectPoiDateByName(request));
    }

    @PostMapping("/query/poi/street/data")
    @ApiOperation(value = "管理后台-查询点面数据")
    public Result<?> poiSelectData(@Validated @RequestBody DataQueryRequest request) {
        return Result.okData(poiScenarioAdminService.selectPoiAndPolygonData(request));
    }

    @PostMapping("/query/poi/microGrid/data")
    @ApiOperation(value = "管理后台-查询具体微网格下的点面数据")
    public Result<?> poiSelectMicroGridData(@Validated @RequestBody MicroDataRequest request) {
        return Result.okData(poiScenarioAdminService.selectPoiAndPolygonMicroData(request));
    }

    @PostMapping("/selectMicroGridBaseInfo")
    @ApiOperation(value = "查询微网格看管划分基本信息", notes = "sgc")
    public Result<?> selectMicroGridBaseInfo(@Validated @RequestBody MicroGridCodeRequest request) {
        MicroGridBaseInfoVo data = poiScenarioAdminService.selectMicroGridBaseInfo(request);
        return Result.okData(data);
    }

    /**
     * 微网格中新增边界并进行看管分配
     *
     * @param request
     * @return
     */
    @PostMapping("/save/boundary")
    public Result<?> addBoundary(@Validated @RequestBody PolygonRequest request) {
        poiScenarioAdminService.addBoundary(request);
        return Result.ok();
    }

    /**
     * 微网格中调整边界
     */
    @PostMapping("/adjust/boundary")
    public Result<?> adjustBoundary(@Validated @RequestBody PolygonRequest request) throws ParseException {
        return Result.okData(poiScenarioAdminService.adjustBoundary(request));
    }

    /**
     * 删除边界
     *
     * @param id
     * @return
     */
    @GetMapping("/delete/boundary")
    public Result<?> deleteBoundary(@Validated @RequestParam(value = "id") String id) {
        return Result.okData(poiScenarioAdminService.deleteBoundary(id));
    }

    /**
     * 复制边界
     * @param request
     * @return
     */
    @PostMapping("/copy/boundary")
    public Result<?> copyBoundary(@Validated @RequestBody PolygonRequest request) {
        return Result.okData(poiScenarioAdminService.copyBoundary(request));
    }

    @ApiOperation("查询面中是否存在被看管的点")
    @PostMapping("/hasInAoiAndCare")
    public Result<?> hasInAoiAndCare(@Validated @RequestBody IdInAoiAndCareListRequest request) {
        boolean has =  poiScenarioAdminService.hasInAoiAndCare(request);
        return Result.okData(has);
    }

}
